基本设定
-
host IP: 192.168.1.254, gateway: 192.168.1.1(OpenWRT)
-
container IP: 192.168.1.1, gateway: DHCP from upstream
ARMBIAN设置
1 软件准备
-
docker import https://downloads.openwrt.org/releases/18.06.2/targets/armvirt/64/openwrt-18.06.2-armvirt-64-default-rootfs.tar.gz openwrt:18.06.2
2 网络设置
-
vi /etc/network/interfaces
-
iface eth0 inet dhcp
-
up ip link set eth0 promisc on
-
vi /etc/network/interfaces.d/bridge
-
auto br-lan
-
iface br-lan inet static
-
address 192.168.1.254
-
netmask 255.255.255.0
-
gateway 192.168.1.1
-
dns-nameservers 192.168.1.1
-
bridge_ports wlan0
3 启动WiFi(2.4G)
-
vi /etc/default/hostapd
-
...
-
DAEMON_CONF="/etc/hostapd.conf"
-
...
-
vi /etc/hostapd.conf
-
...
-
interface=wlan0
-
bridge=br-lan
-
driver=nl80211
4 N1重启后,新建container与配套网络
-
docker network create -d bridge --subnet 192.168.1.0/24 --gateway=192.168.1.254 -o "com.docker.network.bridge.name=br-lan" lanet
-
docker run -d --name N1 --network lanet --privileged openwrt:18.06.2 /sbin/init
-
docker network create -d macvlan -o parent=eth0 wanet
-
docker network connect wanet N1
-
docker exec -it N1 sh
复制代码
**Container(**OpenWRT)设置
网络设置
-
vi /etc/config/network
-
...
-
config interface 'wan'
-
option ifname 'eth1'
-
option proto 'dhcp'
-
config interface 'wan6'
-
option ifname '@wan'
-
option proto 'dhcpv6'
复制代码
ARMBIAN设置
1 重启N1后,手工启动container
-
docker start N1
复制代码
2 更换缺省路由到OpenWRT,确认网络环境正常: 手机可以看到N1放出的ARMBIAN 无线信号,用密码 12345678 登入后应能正常上网。网络设置里可以看到gateway为192.168.1.1
确认一切正常?设置container自动重启
-
docker update --restart always N1
复制代码
3 确认/etc/resolv.conf内nameserver 指向正确的IP(按本文设置应该是192.168.1.1):设置docker后DHCP获取上级网络信息往往出问题,导致docker内openwrt DNS不能正常解析。
4 最后重启N1,设置全部完成。
登入N1的无线网络后,可以通过 http://openwrt 访问路由器。